package org.utils;

import org.compiere.model.MReconciliationAct;
import org.compiere.process.DocAction;

public class WorkFlowHelper {
	public static String Posted()
	{
		//do something
		return " ";
	}
	
	public static boolean ProcessIt(String action, MReconciliationAct contract)
	{
		if(DocAction.ACTION_Post.equals(action))
		{
			return postIt(contract);
		}
		
		else if(DocAction.ACTION_Approve.equals(action))
		{
			return approveIt(contract);
		}
		
		else if(DocAction.ACTION_Complete.equals(action))
		{
			return completeIt(contract);
		}
		else if(DocAction.ACTION_Void.equals(action))
		{
			return voidIt(contract);
		}
		else if(DocAction.ACTION_WaitComplete.equals(action))
		{
			return waitCompleteIt(contract);
		}
		else if(DocAction.ACTION_ReActivate.equals(action))
		{
			return reActivateIt(contract);
		}
		else if(DocAction.ACTION_Prepare.equals(action))
		{
			return prepareIt(contract);
		}
		else if(DocAction.ACTION_Invalidate.equals(action))
		{
			return invalidateIt(contract);
		}
		return false;
	}
	

	//Исполнен
	private static boolean postIt(MReconciliationAct contract)
	{
		contract.setDocStatus("PO");
		contract.setProcessed(true);
		return true;
	}
	//Выполнен
	private static boolean approveIt(MReconciliationAct contract)
	{
		contract.setDocStatus("AP");
		contract.setProcessed(true);
		return true;
	}
	//Подписан
	private static boolean completeIt(MReconciliationAct contract)
	{
		if(contract.isProcessed())
		{
			contract.setDocAction(contract.getDocStatus());
			return true;
		}
			contract.setDocStatus("CO");
		return true;
	}
	//Расторгнут
	private static boolean voidIt(MReconciliationAct contract)
	{
		contract.setDocStatus("VO");
		contract.setProcessed(true);
		return true;
	}
	//На согласовании
	private static boolean waitCompleteIt(MReconciliationAct contract)
	{
		if(contract.isProcessed())
		{
			contract.setDocAction(contract.getDocStatus());
			return true;
		}
			contract.setDocStatus("WC");
		return true;
	}
	//Отменен
	private static boolean reActivateIt(MReconciliationAct contract)
	{
		if(contract.isProcessed())
		{
			contract.setDocAction(contract.getDocStatus());
			return true;
		}
			contract.setDocStatus("RE");
		return true;
	}
	//Проект
	private static boolean prepareIt(MReconciliationAct contract)
	{
		if(contract.isProcessed())
		{
			contract.setDocAction(contract.getDocStatus());
			return true;
		}
			contract.setDocStatus("PR");
		return true;
	}
	//Действует
	private static boolean invalidateIt(MReconciliationAct contract)
	{
		contract.setDocStatus("IN");
		contract.setProcessed(true);
		return true;
	}
}
